package de.haw.shc.Room;

import android.app.ActionBar;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import de.haw.shc.Config.TabsAdapter;
import de.haw.shc.Config.XML_Reader;
import de.haw.shc.Interfaces.DeviceProperty.Device;
import de.haw.shc.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: mizus
 * Date: 11.06.13
 * Time: 11:28
 * To change this template use File | Settings | File Templates.
 */
public class RaumActivity extends FragmentActivity {




    private List<String> list_room;
    private final List<Integer> list_icon = Arrays.asList(R.drawable.schlafen,  R.drawable.dinner, R.drawable.kitchen,
            R.drawable.wc, R.drawable.lounge,  R.drawable.corridor);
    private List<List<RoomItem>> itemLists = null;


    public class RoomItem{
        public String name;
    }


    @Override
    public void onCreate(Bundle bundle){
        super.onCreate(bundle);
        setContentView(R.layout.pagerview);
        XML_Reader xml_reader = XML_Reader.createXMLReader(getResources());
        Map<String, List<Device>> roomMap = xml_reader.getRaumMap();

        list_room = new ArrayList<String>(roomMap.keySet());

        buildTabs();
    }



    private void buildTabs() {
        ViewPager viewPager = new ViewPager(this);
        viewPager.setId(R.id.pager);

        setContentView(viewPager);

        ActionBar bar = getActionBar();
        // Create a new Action bar and set title to strings.xml

        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        bar.setTitle(R.string.app_title);

        // Attach the Tabs to the fragment classes and set the tab title.
        TabsAdapter tabsAdapter = new TabsAdapter(this, viewPager);

        for (int i = 0; i < list_room.size(); i++) {
            Bundle bundle = new Bundle();
            bundle.putString("Room", list_room.get(i));

            viewPager.setOffscreenPageLimit(i);
            bundle.putInt("index", i);
            tabsAdapter.addTab(bar.newTab().setText(""), RoomItemFragment.class, bundle, list_icon.get(i) , getResources().getInteger(R.integer.room));
        }
    }



}
